set scheme s2mono
*********************************************
****   Description   ************************
*********************************************

*This program runs a differences-in-differences analysis comparing the number of new accounts opened at the D.C branch, which had close ties with the leading African-American jounral, to other branches of the Freedman's Savings Bank before and after the 1870 charter amendment, generating "Figure 5. Advertising and Deposit Collection - Difference-in-Differences Analysis". 



* Macros
global cluster cluster(branch mo_date)
global fe branch mo_date


****   Data   *******************************
*********************************************
use "$Data/Account_Panel_Monthly_December2024.dta", clear
drop if mo_date > tm(1873m8)

*Create Variables
gen quarter = qofd(dofm(mo_date))
format quarter %tq 
gen high_ad_relation=branch=="Washington"

sort branch quarter


*********************************************
****   Diff in Diff  ************************ 
*********************************************


///  Create before and after treatment 
gen treatante17 = (quarter ==  tq(1866q1) & high_ad_relation ==1)
gen treatante16 = (quarter ==  tq(1866q2) & high_ad_relation ==1)
gen treatante15 = (quarter ==  tq(1866q3) & high_ad_relation ==1)
gen treatante14 = (quarter ==  tq(1866q4) & high_ad_relation ==1)
gen treatante13 = (quarter ==  tq(1867q1) & high_ad_relation ==1)
gen treatante12 = (quarter ==  tq(1867q2) & high_ad_relation ==1)
gen treatante11 = (quarter ==  tq(1867q3) & high_ad_relation ==1)
gen treatante10 = (quarter ==  tq(1867q4) & high_ad_relation ==1)
gen treatante9 = (quarter ==  tq(1868q1) & high_ad_relation ==1)
gen treatante8 = (quarter ==  tq(1868q2) & high_ad_relation ==1)
gen treatante7 = (quarter ==  tq(1868q3) & high_ad_relation ==1)
gen treatante6 = (quarter ==  tq(1868q4) & high_ad_relation ==1)
gen treatante5 = (quarter ==  tq(1869q1) & high_ad_relation ==1)
gen treatante4 = (quarter ==  tq(1869q2) & high_ad_relation ==1)
gen treatante3 = (quarter ==  tq(1869q3) & high_ad_relation ==1)
gen treatante2 = (quarter ==  tq(1869q4) & high_ad_relation ==1)
gen treatante1 = (quarter ==  tq(1870q1) & high_ad_relation ==1)
  
gen treatquarter = (quarter ==  tq(1870q2) & high_ad_relation ==1)
gen treatpost1 = (quarter ==  tq(1870q3) & high_ad_relation ==1)
gen treatpost2 = (quarter ==  tq(1870q4) & high_ad_relation ==1)
gen treatpost3 = (quarter ==  tq(1871q1) & high_ad_relation ==1)
gen treatpost4 = (quarter == tq(1871q2) & high_ad_relation ==1)
gen treatpost5 = (quarter == tq(1871q3) & high_ad_relation ==1)
gen treatpost6 = (quarter == tq(1871q4) & high_ad_relation ==1)
gen treatpost7 = (quarter == tq(1872q1) & high_ad_relation ==1)
gen treatpost8 = (quarter == tq(1872q2) & high_ad_relation ==1)
gen treatpost9 = (quarter == tq(1872q3) & high_ad_relation ==1)
gen treatpost10 = (quarter == tq(1872q4) & high_ad_relation ==1)
gen treatpost11 = (quarter == tq(1873q1) & high_ad_relation ==1)
gen treatpost12 = (quarter == tq(1873q2) & high_ad_relation ==1)
gen treatpost13 = (quarter == tq(1873q3) & high_ad_relation ==1)
gen treatpost14 = (quarter == tq(1873q4) & high_ad_relation ==1)


global treatment  treatante17  treatante16 treatante15 treatante14 treatante13 treatante12 treatante11 treatante10 treatante9 treatante8 treatante7 treatante6 treatante5 treatante4 treatante3 treatante2 treatante1 treatquarter treatpost1 treatpost2 treatpost3 treatpost4 treatpost5 treatpost6 treatpost7 treatpost8 treatpost9 treatpost10 treatpost11 treatpost12 treatpost13    

//Regression
eststo: reghdfe num_account  $treatment  , absorb($fe) $cluster
local tt=_b[treatante1]

//Graph
coefplot , keep($treatment) recast(line)  lcolor(black) lwidth(medthick)  omitted baselevel vertical transform(* = @-`tt')  graphregion( color(white) )    ///
level(95) msymbol(D)  mcolor(black) xline(17, lwidth(thick) ) yline(0, lstyle(foreground) lcolor(black) lpattern(solid)) ///
  title(" ") ///
  ylab(, nogrid) ///
  xlabel(1 "1866Q1" 5 "1867Q1" 9 "1868Q1" 13 "1869Q1" 17 "1870Q1" 21 "1871Q1" 25 "1872Q1" 29 "1873Q1" ) 
 
